﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Warehouse.Application.Dto.Input;
using Warehouse.Application.Dto.Output;
using Warehouse.Application.Services.Libraryrecord;
using Warehouse.Domain.Entities;
using Warehouse.Result;

namespace Warehouse.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class LibraryrecordController : ControllerBase
    {
        private readonly ILibraryrecordAppService _libraryrecordAppService;

        public LibraryrecordController(ILibraryrecordAppService libraryrecordAppService)
        {
            _libraryrecordAppService = libraryrecordAppService;
        }

        /// <summary>
        /// 添加出入库的库存
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public ApiResult<int> CreateLibraryrecord(CreateLibraryrecordInput input)
        {
            return _libraryrecordAppService.CreateLibraryrecord(input);
        }

        /// <summary>
        /// 获取出入库的库存
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        public ApiPaing<LibraryrecordOutput> GetLibraryrecord([FromQuery]LibraryrecordInput input)
        {
            return _libraryrecordAppService.GetLibraryrecord(input);
        }

        /// <summary>
        /// 出库
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpPost]
        public ApiResult<int> OutLibraryrecord(OutLibraryrecordInput input)
        {
            return _libraryrecordAppService.OutLibraryrecord(input);
        }

        /// <summary>
        /// 流水查询
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        public ApiPaing<SpringWaterOutput> GetApringWater([FromQuery]GetApringWaterInput input)
        {
            return _libraryrecordAppService.GetApringWater(input);
        }


        /// <summary>
        /// 获取时间生成距状图
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public object PayMoney()
        {
            return _libraryrecordAppService.PayMoney();
        }

        /// <summary>
        /// 获取7天时间生成距状图
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public object PayMoneyday()
        {
            return _libraryrecordAppService.PayMoneyday();
        }

        /// <summary>
        /// 获取30天时间生成距状图
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public object PayMoneyMonth()
        {
            return _libraryrecordAppService.PayMoneyMonth();
        }

        /// <summary>
        /// 更新每日仓库统计数据
        /// </summary>
        /// <param name="date">指定日期，默认为今天</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<bool>> UpdateDailyStatistics(DateTime? date = null)
        {
            return await _libraryrecordAppService.UpdateDailyStatistics(date);
        }

        /// <summary>
        /// 查询当天的统计
        /// </summary>
        /// <param name="Jtime"></param>
        /// <returns></returns>
        [HttpGet]
        public ApiResult<WideTableModel> GetWideTable(DateTime Jtime)
        {
            return _libraryrecordAppService.GetWideTable(Jtime);
        }


    }
}
